package org.artifact.core.plugin.jedis;

import cn.hutool.db.nosql.redis.RedisDS;
import cn.hutool.setting.Setting;
import org.artifact.core.lang.AbstractPlugin;
import org.artifact.core.lang.RedisScript;
import org.artifact.core.server.ServerConfig;
import redis.clients.jedis.Jedis;

import java.util.Map;

/**
 * @author : SandKing
 * @CreateDate : 2020/3/14 19:02
 * @Description ：Please describe this document
 */
public class JedisPlugin extends AbstractPlugin {

    private RedisDS redisDS;

    @Override
    public boolean start() {
    	Map jedis = ServerConfig.me().deepGet("plugins.jedis");
        Setting setting = new Setting();

        jedis.forEach((k,v)->{
            setting.put(k.toString(),v.toString());
        });


        redisDS = new RedisDS(setting,null);

        RedisScript.init(redisDS.getJedis());
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }
    
    public Jedis getJedis() {
    	return redisDS.getJedis();
    }
}
